package cn.com.myshiro.controller;

import java.util.List;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import Test.tools.Page;
import java.util.Map;
import java.util.HashMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import cn.com.myshiro.bean.Sysrolepermission;
import cn.com.myshiro.service.SysrolepermissionService;

@Controller
public class SysrolepermissionController {

      @Autowired
      SysrolepermissionService service;

      @RequestMapping(value = "/sysrolepermissionView.do")
      public String sysrolepermissionView(ModelMap modelMap,String pageNo, String choice, HttpSession session){
			int currentPage = 1;
			if (pageNo != null) {
				currentPage = Integer.parseInt(pageNo);
			}
			int countNum = service.countSysrolepermission();
			Page _page = new Page(5, countNum, currentPage);
			_page.setTotalRecord(countNum);
			_page.setPageNumStart(_page.getPageNumStart());
			_page.setPageNumEnd(_page.getPageNumEnd());
			_page.setCurrentPage(currentPage);
			Map<Object,Object> map = new HashMap<Object,Object>();
			map.put("nowpage", _page.getStart());
			map.put("pagesize", _page.getPageRecord());
			List<Sysrolepermission> sysrolepermissionList = null;
			try {
				sysrolepermissionList = service.allSysrolepermission(map);
			} catch (Exception e) {
				e.printStackTrace();
			}
			modelMap.put("sysrolepermissionList", sysrolepermissionList);
			modelMap.put("showPage", _page);
          return "back/jsp/sysrolepermission/sysrolepermissionView";
     }

      @RequestMapping(value = "/sysrolepermissionDel{id}.do")
      public String sysrolepermissionDel(@PathVariable("id")int id ,ModelMap modelMap,String pageNo, String choice, HttpSession session){
             service.delSysrolepermission(id);
             String message1="删除成功";
             String message2="请返回……";
             modelMap.put("message1", message1);
             modelMap.put("message2", message2);
            return "redirect:/sysrolepermissionView.do";
      }

      @RequestMapping(value ="/sysrolepermissionGoAdd.do")
             public String sysrolepermissionGoAdd(ModelMap modelMap,String pageNo, String choice, HttpSession session){
             return "back/jsp/sysrolepermission/sysrolepermissionAdd";
      }

      @RequestMapping(value = "/sysrolepermissionAdd.do",method=RequestMethod.POST)
      public String sysrolepermissionAdd(Sysrolepermission form,ModelMap modelMap,String pageNo, String choice, HttpSession session){
             service.addSysrolepermission(form);
             String message1="添加成功";
             String message2="请返回……";
             String  url="sysrolepermissionView.do";
             modelMap.put("message1", message1);
             modelMap.put("message2", message2);
             modelMap.put("url", url);
             return "redirect:/sysrolepermissionView.do";
      }

      @RequestMapping(value = "/sysrolepermissionGoUpdate{id}.do")
      public String sysrolepermissionGoUpdate(@PathVariable("id")int id ,ModelMap modelMap,String pageNo, String choice, HttpSession session){
             Sysrolepermission sysrolepermission = service.sysrolepermission(id);
             modelMap.put("sysrolepermission", sysrolepermission);
             return "back/jsp/sysrolepermission/sysrolepermissionUpdate";
      }

      @RequestMapping(value = "/sysrolepermissionUpdate.do",method=RequestMethod.POST)
      public String sysrolepermissionUpdate(Sysrolepermission form,ModelMap modelMap,String pageNo, String choice, HttpSession session){
             service.updateSysrolepermission(form);
             String message1="修改成功";
             String message2="请返回……";
             String  url="sysrolepermissionView.do";
             modelMap.put("message1", message1);
             modelMap.put("message2", message2);
             modelMap.put("url", url);
             return "redirect:/sysrolepermissionView.do";
      }

 }
